home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / GRAPHICS / NEWPAPER.ZIP / NEWPAPER.C < prev    next >
C/C++ Source or Header  |  1993-10-24  |  4KB  |  109 lines

  1. /*----------------------------------------------------------------------*
  2.  | Filename:    NEWPAPER.C                                              |
  3.  |                                                                      |
  4.  | Description: Windows 3.1 application to change the Windows wallpaper |
  5.  |              to the 'next' .BMP file found in the current working    |
  6.  |              directory.                                              |
  7.  |                                                                      |
  8.  | Notes:       1. If no wallpaper setting in WIN.INI, it does nothing  |
  9.  |              2. Looks for *.BMP files in 'working directory' as set  |
  10.  |                 in File | Properties.  If no *.BMP files, it does    |
  11.  |                 nothing.                                             |
  12.  |              3. It remembers the first *.BMP file found and then     |
  13.  |                 checks the list of *.BMP files against the current   |
  14.  |                 *.BMP setting.  When it finds the current one, it    |
  15.  |                 selects the next one.  If it doesn't find the current|
  16.  |                 one or if the current one is the last one, it uses   |
  17.  |                 the first one found.                                 |
  18.  |                                                                      |
  19.  | Author:      John A. Grant                                           |
  20.  |              Geological Survey of Canada                             |
  21.  |              Mineral Resources Division                              |
  22.  |              Airborne Geophysics Section                             |
  23.  |              601 Booth St., Room 591                                 |
  24.  |              Ottawa, Ontario, K1A 0E8                                |
  25.  |              (613) 992-1082                                          |
  26.  |              jagrant@gsc.emr.ca                                      |
  27.  |                                                                      |
  28.  | Copyright:   None.  This code is hereby released into the public     | 
  29.  |              domain.  You may do with it as you wish.                |
  30.  *----------------------------------------------------------------------*/
  31. //standard function prototypes
  32.     #define STRICT
  33.     #include <windows.h>
  34.     #include <stdlib.h>             //_fullpath
  35.     #include <string.h>             //strcpy
  36.     #include <dir.h>                //findfirst
  37.  
  38. //constants
  39.     #define NUL             '\0'
  40.     #define MAX_L_PATHNAME  256
  41.     #define INI_SECTION     "Desktop"
  42.     #define INI_ENTRY       "Wallpaper"
  43.  
  44. //local function prototypes
  45.     static BOOL ChangeWallpaper(void);
  46.  
  47. /*----------------------------------------------------------------------*
  48.  | main windows procedure                                               |
  49.  *----------------------------------------------------------------------*/
  50. #pragma argsused
  51. int PASCAL WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,
  52.                 LPSTR cmdline,int showtype)
  53. {
  54.     return(ChangeWallpaper());
  55. }
  56.  
  57.  
  58. /*----------------------------------------------------------------------*
  59.  |                                                                      |
  60.  *----------------------------------------------------------------------*/
  61. BOOL ChangeWallpaper(void)
  62. {
  63. char current [MAX_L_PATHNAME+1];
  64. char newpaper[MAX_L_PATHNAME+1];
  65. struct ffblk stuff;
  66. BOOL done,takenextone,result;
  67.  
  68.     result=FALSE;
  69.  
  70.     //ignore if no wallpaper set
  71.     *current=NUL;
  72.     GetProfileString(INI_SECTION,INI_ENTRY,"",current,sizeof(current));
  73.     if(*current==NUL) goto bye;
  74.  
  75.     //ignore if no bmp files
  76.     done=findfirst("*.bmp",&stuff,0);
  77.     if(done) goto bye;
  78.  
  79.     //convert pathname of current wallpaper bitmap to simple filename
  80.     fnsplit(current,NULL,NULL,newpaper,NULL);
  81.     strcpy(current,newpaper);
  82.     strcat(current,".bmp");
  83.  
  84.     //find current name and pick the next one
  85.     strcpy(newpaper,stuff.ff_name);         //remember first name
  86.  
  87.     takenextone=FALSE;
  88.     while(!done){ 
  89.       if(takenextone){
  90.         strcpy(newpaper,stuff.ff_name);
  91.         done=TRUE;
  92.       }else{
  93.         takenextone=stricmp(current,stuff.ff_name)==0;
  94.         done=findnext(&stuff);
  95.       }
  96.     }
  97.     
  98.     //convert filename to pathname
  99.     _fullpath(current,newpaper,sizeof(current));
  100.  
  101.     //set new wallpaper pathname
  102.     //MessageBox(NULL,current,"New Wallpaper",MB_OK | MB_ICONINFORMATION);
  103.     SystemParametersInfo(SPI_SETDESKWALLPAPER,0,current,SPIF_UPDATEINIFILE);
  104.  
  105.     result=TRUE;
  106.  
  107. bye:    return(result);
  108. }
  109.